import type { Sequelize } from 'sequelize';
import { AiChatConversations as _AiChatConversations } from './AiChatConversations';
import type {
  AiChatConversationsAttributes,
  AiChatConversationsCreationAttributes,
} from './AiChatConversations';
import { AiChatMessages as _AiChatMessages } from './AiChatMessages';
import type {
  AiChatMessagesAttributes,
  AiChatMessagesCreationAttributes,
} from './AiChatMessages';
import { FactoryBase as _FactoryBase } from './FactoryBase';
import type {
  FactoryBaseAttributes,
  FactoryBaseCreationAttributes,
} from './FactoryBase';
import { FactoryToyItem as _FactoryToyItem } from './FactoryToyItem';
import type {
  FactoryToyItemAttributes,
  FactoryToyItemCreationAttributes,
} from './FactoryToyItem';
import { FactoryToyManual as _FactoryToyManual } from './FactoryToyManual';
import type {
  FactoryToyManualAttributes,
  FactoryToyManualCreationAttributes,
} from './FactoryToyManual';
import { Label as _Label } from './Label';
import type { LabelAttributes, LabelCreationAttributes } from './Label';
import { Subject as _Subject } from './Subject';
import type { SubjectAttributes, SubjectCreationAttributes } from './Subject';
import { User as _User } from './User';
import type { UserAttributes, UserCreationAttributes } from './User';
import { UserToyItem as _UserToyItem } from './UserToyItem';
import type {
  UserToyItemAttributes,
  UserToyItemCreationAttributes,
} from './UserToyItem';
import { WeixinUser as _WeixinUser } from './WeixinUser';
import type {
  WeixinUserAttributes,
  WeixinUserCreationAttributes,
} from './WeixinUser';
import { WxAiChatMessages as _WxAiChatMessages } from './WxAiChatMessages';
import type {
  WxAiChatMessagesAttributes,
  WxAiChatMessagesCreationAttributes,
} from './WxAiChatMessages';

export {
  _AiChatConversations as AiChatConversations,
  _AiChatMessages as AiChatMessages,
  _FactoryBase as FactoryBase,
  _FactoryToyItem as FactoryToyItem,
  _FactoryToyManual as FactoryToyManual,
  _Label as Label,
  _Subject as Subject,
  _User as User,
  _UserToyItem as UserToyItem,
  _WeixinUser as WeixinUser,
  _WxAiChatMessages as WxAiChatMessages,
};

export type {
  AiChatConversationsAttributes,
  AiChatConversationsCreationAttributes,
  AiChatMessagesAttributes,
  AiChatMessagesCreationAttributes,
  FactoryBaseAttributes,
  FactoryBaseCreationAttributes,
  FactoryToyItemAttributes,
  FactoryToyItemCreationAttributes,
  FactoryToyManualAttributes,
  FactoryToyManualCreationAttributes,
  LabelAttributes,
  LabelCreationAttributes,
  SubjectAttributes,
  SubjectCreationAttributes,
  UserAttributes,
  UserCreationAttributes,
  UserToyItemAttributes,
  UserToyItemCreationAttributes,
  WeixinUserAttributes,
  WeixinUserCreationAttributes,
  WxAiChatMessagesAttributes,
  WxAiChatMessagesCreationAttributes,
};

export function initModels(sequelize: Sequelize) {
  const AiChatConversations = _AiChatConversations.initModel(sequelize);
  const AiChatMessages = _AiChatMessages.initModel(sequelize);
  const FactoryBase = _FactoryBase.initModel(sequelize);
  const FactoryToyItem = _FactoryToyItem.initModel(sequelize);
  const FactoryToyManual = _FactoryToyManual.initModel(sequelize);
  const Label = _Label.initModel(sequelize);
  const Subject = _Subject.initModel(sequelize);
  const User = _User.initModel(sequelize);
  const UserToyItem = _UserToyItem.initModel(sequelize);
  const WeixinUser = _WeixinUser.initModel(sequelize);
  const WxAiChatMessages = _WxAiChatMessages.initModel(sequelize);

  FactoryToyItem.belongsTo(FactoryBase, {
    as: 'factory',
    foreignKey: 'factoryId',
  });
  FactoryBase.hasMany(FactoryToyItem, {
    as: 'factoryToyItems',
    foreignKey: 'factoryId',
  });
  FactoryToyManual.belongsTo(FactoryToyItem, {
    as: 'toy',
    foreignKey: 'toyId',
  });
  FactoryToyItem.hasMany(FactoryToyManual, {
    as: 'factoryToyManuals',
    foreignKey: 'toyId',
  });
  UserToyItem.belongsTo(FactoryToyItem, { as: 'toy', foreignKey: 'toyId' });
  FactoryToyItem.hasMany(UserToyItem, {
    as: 'userToyItems',
    foreignKey: 'toyId',
  });

  return {
    AiChatConversations: AiChatConversations,
    AiChatMessages: AiChatMessages,
    FactoryBase: FactoryBase,
    FactoryToyItem: FactoryToyItem,
    FactoryToyManual: FactoryToyManual,
    Label: Label,
    Subject: Subject,
    User: User,
    UserToyItem: UserToyItem,
    WeixinUser: WeixinUser,
    WxAiChatMessages: WxAiChatMessages,
  };
}
